package com.kilim.idea;

import org.springframework.util.StopWatch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/**
 * @projectName: learn_used_code
 * @packageName: com.kilim.idea
 * @className: com.kilim.idea-> TestKilim
 * @createDate: 2021-12-15 17:27
 * @author: ZhangSheng
 * @version: 1.0
 * @description:
 */
public class TestThreadDemo {


    public static void main(String[] args) throws Exception{
        CountDownLatch count  = new CountDownLatch(100000);
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        ExecutorService executorService = Executors.newCachedThreadPool();
        IntStream.range(0,100000).forEach(i-> executorService.submit(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException ex) { }
            count.countDown();
        }));
        count.await();
        stopWatch.stop();
        System.out.println("结束了: " + stopWatch.prettyPrint());
    }
}
